# 日志用的
import time
import os
import logging
from logging.handlers import SMTPHandler, RotatingFileHandler


def register_logging(app,basedir):
    app.logger.setLevel(logging.INFO)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    file_handler = RotatingFileHandler(os.path.join(
        basedir, 'storage/logs/logger-' + time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log'), maxBytes=10 * 1024 * 1024, backupCount=100)
    file_handler.setFormatter(formatter)
    file_handler.setLevel(logging.INFO)
    if not app.debug:
        app.logger.addHandler(file_handler)
